<template>
  <div class="moments-app" :class="{ 'dark-theme': isDarkTheme }">
    <!-- 顶部个人信息区 -->
    <div class="profile-header">
      <div class="cover-image"></div>
      <div class="user-info">
        <div class="avatar"></div>
        <div class="username">KyCloud</div>
      </div>
      <!-- 主题切换按钮 -->
      <button class="theme-toggle" @click="toggleTheme" :title="isDarkTheme ? '切换到浅色模式' : '切换到深色模式'">
        <span class="theme-icon">{{ isDarkTheme ? '☀️' : '🌙' }}</span>
      </button>
    </div>

    <!-- 标签筛选栏 -->
    <div class="filter-bar" v-if="allTags.length > 0">
      <button
        @click="selectedTag = null"
        class="tag-filter"
        :class="{ active: selectedTag === null }"
      >
        全部
      </button>
      <button
        v-for="tag in allTags"
        :key="tag"
        @click="selectedTag = tag"
        class="tag-filter"
        :class="{ active: selectedTag === tag }"
      >
        {{ tag }}
      </button>
    </div>

    <!-- 动态列表 -->
    <div class="moments-list">
      <!-- 按月份分组 -->
      <template v-for="(group, index) in groupedMoments" :key="group.month">
        <div class="month-divider">
          <span class="month-text">{{ group.month }}</span>
        </div>
        <div v-for="moment in group.moments" :key="moment.id" class="moment-item">
        <div class="moment-avatar"></div>
        <div class="moment-content">
          <div class="moment-username">KyCloud</div>

          <!-- 文本内容 -->
          <div class="moment-text" v-if="moment.text">{{ moment.text }}</div>

          <!-- 图片 -->
          <div class="moment-images" v-if="moment.images && moment.images.length > 0">
            <div
              v-for="(image, index) in moment.images"
              :key="index"
              class="image-wrapper"
              :class="'image-count-' + moment.images.length"
            >
              <img :src="image" :alt="'图片' + (index + 1)" />
            </div>
          </div>

          <!-- 地点和标签 -->
          <div class="moment-meta" v-if="moment.location || (moment.tags && moment.tags.length > 0)">
            <div class="moment-location" v-if="moment.location">
              <span class="location-icon">📍</span>
              <span class="location-text">{{ moment.location }}</span>
            </div>
            <div class="moment-tags" v-if="moment.tags && moment.tags.length > 0">
              <span
                v-for="tag in moment.tags"
                :key="tag"
                class="tag"
                @click="selectedTag = tag"
              >
                {{ tag }}
              </span>
            </div>
          </div>

          <!-- 链接 -->
          <a
            v-if="moment.link"
            :href="moment.link"
            target="_blank"
            class="moment-link"
          >
            <div class="link-icon">🔗</div>
            <div class="link-text">{{ moment.link }}</div>
          </a>

          <div class="moment-footer">
            <span class="moment-time">{{ formatTime(moment.createdAt) }}</span>
            <div class="moment-actions">
              <button
                @click="toggleLike(moment.id)"
                class="like-btn"
                :class="{ liked: moment.liked }"
              >
                <span class="like-icon">{{ moment.liked ? '❤️' : '🤍' }}</span>
                <span v-if="moment.likes > 0">{{ moment.likes }}</span>
              </button>
            </div>
          </div>
        </div>
        </div>
      </template>

      <!-- 空状态 -->
      <div v-if="moments.length === 0" class="empty-state">
        <div class="empty-icon">📝</div>
        <p>还没有记录任何瞬间</p>
        <p>点击右下角按钮开始记录吧</p>
      </div>

      <!-- 筛选后无结果 -->
      <div v-else-if="filteredMoments.length === 0" class="empty-state">
        <div class="empty-icon">🔍</div>
        <p>没有找到相关内容</p>
      </div>
    </div>

    <!-- 发布按钮 -->
    <button class="post-btn" @click="showPostDialog = true">
      <span class="post-icon">✏️</span>
    </button>

    <!-- 发布弹窗 -->
    <div v-if="showPostDialog" class="dialog-overlay" @click="closeDialog">
      <div class="dialog-content" @click.stop>
        <div class="dialog-header">
          <h3>记录此刻</h3>
          <button class="close-btn" @click="closeDialog">✕</button>
        </div>

        <div class="dialog-body">
          <textarea
            v-model="newMoment.text"
            placeholder="此刻的心情、想法..."
            class="text-input"
            rows="5"
          ></textarea>

          <div class="input-group">
            <label>图片</label>

            <!-- 已添加的图片列表 -->
            <div v-if="newMoment.images.length > 0" class="image-list">
              <div
                v-for="(image, index) in newMoment.images"
                :key="index"
                class="image-item"
              >
                <div class="image-preview">
                  <img :src="image" alt="预览图" @error="handleImageError($event, index)" />
                </div>
                <div class="image-url">{{ truncateUrl(image) }}</div>
                <button
                  @click="removeImage(index)"
                  class="remove-image-btn"
                  type="button"
                >
                  ✕
                </button>
              </div>
            </div>

            <!-- 添加图片 -->
            <div class="add-image-section">
              <input
                v-model="currentImageUrl"
                type="text"
                placeholder="粘贴图片链接后按回车或点击添加"
                class="url-input"
                @keyup.enter="addImage"
              />
              <button
                @click="addImage"
                class="add-image-btn"
                type="button"
                :disabled="!currentImageUrl.trim()"
              >
                添加
              </button>
            </div>
            <div class="image-hint">最多可添加9张图片</div>
          </div>

          <div class="input-group">
            <label>标签</label>

            <!-- 已添加的标签 -->
            <div v-if="newMoment.tags.length > 0" class="tags-list">
              <span
                v-for="(tag, index) in newMoment.tags"
                :key="index"
                class="tag-item"
              >
                {{ tag }}
                <button
                  @click="removeTag(index)"
                  class="remove-tag-btn"
                  type="button"
                >
                  ✕
                </button>
              </span>
            </div>

            <!-- 添加标签 -->
            <div class="add-tag-section">
              <input
                v-model="currentTag"
                type="text"
                placeholder="输入标签后按回车"
                class="url-input"
                @keyup.enter="addTag"
              />
              <button
                @click="addTag"
                class="add-tag-btn"
                type="button"
                :disabled="!currentTag.trim()"
              >
                添加
              </button>
            </div>
            <div class="tag-hint">常用：旅行、美食、风景、日常</div>
          </div>

          <div class="input-group">
            <label>地点</label>
            <input
              v-model="newMoment.location"
              type="text"
              placeholder="在哪里？"
              class="url-input"
            />
          </div>

          <div class="input-group">
            <label>相关链接</label>
            <input
              v-model="newMoment.link"
              type="text"
              placeholder="https://..."
              class="url-input"
            />
          </div>
        </div>

        <div class="dialog-footer">
          <button @click="closeDialog" class="cancel-btn">取消</button>
          <button @click="publishMoment" class="publish-btn">发布</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, computed } from 'vue'

// 动态列表
const moments = ref([])

// 标签筛选
const selectedTag = ref(null)

// 主题
const isDarkTheme = ref(false)

// 发布弹窗
const showPostDialog = ref(false)
const newMoment = ref({
  text: '',
  images: [],
  tags: [],
  location: '',
  link: ''
})
const currentImageUrl = ref('')
const currentTag = ref('')

// 从 localStorage 加载数据
onMounted(() => {
  const saved = localStorage.getItem('kycloud-moments')
  if (saved) {
    moments.value = JSON.parse(saved)
  }

  // 加载主题偏好
  const savedTheme = localStorage.getItem('kycloud-theme')
  if (savedTheme === 'dark') {
    isDarkTheme.value = true
  }
})

// 保存到 localStorage
const saveMoments = () => {
  localStorage.setItem('kycloud-moments', JSON.stringify(moments.value))
}

// 切换主题
const toggleTheme = () => {
  isDarkTheme.value = !isDarkTheme.value
  localStorage.setItem('kycloud-theme', isDarkTheme.value ? 'dark' : 'light')
}

// 获取所有标签
const allTags = computed(() => {
  const tags = new Set()
  moments.value.forEach(moment => {
    if (moment.tags && Array.isArray(moment.tags)) {
      moment.tags.forEach(tag => tags.add(tag))
    }
  })
  return Array.from(tags).sort()
})

// 筛选后的动态
const filteredMoments = computed(() => {
  if (!selectedTag.value) {
    return moments.value
  }
  return moments.value.filter(moment => {
    return moment.tags && moment.tags.includes(selectedTag.value)
  })
})

// 按月份分组
const groupedMoments = computed(() => {
  const groups = {}

  filteredMoments.value.forEach(moment => {
    const date = new Date(moment.createdAt)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const monthKey = `${year}年${month}月`

    if (!groups[monthKey]) {
      groups[monthKey] = {
        month: monthKey,
        timestamp: date.getTime(),
        moments: []
      }
    }
    groups[monthKey].moments.push(moment)
  })

  // 按时间倒序排列
  return Object.values(groups).sort((a, b) => b.timestamp - a.timestamp)
})

// 添加图片
const addImage = () => {
  const url = currentImageUrl.value.trim()
  if (!url) return

  if (newMoment.value.images.length >= 9) {
    alert('最多只能添加9张图片')
    return
  }

  // 简单的URL验证
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
    alert('请输入有效的图片链接（以 http:// 或 https:// 开头）')
    return
  }

  newMoment.value.images.push(url)
  currentImageUrl.value = ''
}

// 删除图片
const removeImage = (index) => {
  newMoment.value.images.splice(index, 1)
}

// 添加标签
const addTag = () => {
  let tag = currentTag.value.trim()
  if (!tag) return

  // 自动添加 # 前缀
  if (!tag.startsWith('#')) {
    tag = '#' + tag
  }

  // 检查是否已存在
  if (newMoment.value.tags.includes(tag)) {
    alert('标签已存在')
    return
  }

  newMoment.value.tags.push(tag)
  currentTag.value = ''
}

// 删除标签
const removeTag = (index) => {
  newMoment.value.tags.splice(index, 1)
}

// 图片加载失败处理
const handleImageError = (event, index) => {
  event.target.src = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="100" height="100"%3E%3Crect fill="%23f0f2f5" width="100" height="100"/%3E%3Ctext x="50" y="50" font-size="12" text-anchor="middle" dy=".3em" fill="%23999"%3E加载失败%3C/text%3E%3C/svg%3E'
}

// 截断URL显示
const truncateUrl = (url) => {
  if (url.length > 40) {
    return url.substring(0, 37) + '...'
  }
  return url
}

// 发布动态
const publishMoment = () => {
  if (!newMoment.value.text && newMoment.value.images.length === 0 && !newMoment.value.link) {
    alert('请至少填写一项内容')
    return
  }

  const moment = {
    id: Date.now(),
    text: newMoment.value.text,
    images: [...newMoment.value.images],
    tags: [...newMoment.value.tags],
    location: newMoment.value.location,
    link: newMoment.value.link,
    createdAt: new Date().toISOString(),
    likes: 0,
    liked: false
  }

  moments.value.unshift(moment)
  saveMoments()

  // 重置表单
  newMoment.value = {
    text: '',
    images: [],
    tags: [],
    location: '',
    link: ''
  }
  currentImageUrl.value = ''
  currentTag.value = ''

  showPostDialog.value = false
}

// 关闭弹窗
const closeDialog = () => {
  showPostDialog.value = false
}

// 点赞
const toggleLike = (id) => {
  const moment = moments.value.find(m => m.id === id)
  if (moment) {
    moment.liked = !moment.liked
    moment.likes = moment.liked ? moment.likes + 1 : moment.likes - 1
    saveMoments()
  }
}

// 格式化时间
const formatTime = (dateString) => {
  const date = new Date(dateString)
  const now = new Date()
  const diff = now - date

  const minutes = Math.floor(diff / 60000)
  const hours = Math.floor(diff / 3600000)
  const days = Math.floor(diff / 86400000)

  if (minutes < 1) return '刚刚'
  if (minutes < 60) return `${minutes}分钟前`
  if (hours < 24) return `${hours}小时前`
  if (days < 7) return `${days}天前`

  return date.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric'
  })
}
</script>

<style scoped>
* {
  box-sizing: border-box;
}

.moments-app {
  min-height: 100vh;
  background-color: #f0f2f5;
  padding-bottom: 20px;
  transition: background-color 0.3s ease;

  /* 浅色主题变量 */
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f7f7f7;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border-color: #e5e5e5;
  --link-color: #576b95;
  --accent-color: #667eea;
  --accent-hover: #5568d3;
  --tag-bg: #f0f2f5;
  --tag-color: #667eea;
  --divider-color: #e5e5e5;
}

/* 深色主题 */
.moments-app.dark-theme {
  background-color: #000000;

  --bg-primary: #000000;
  --bg-secondary: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --text-primary: #ffffff;
  --text-secondary: #98989d;
  --text-tertiary: #636366;
  --border-color: #38383a;
  --link-color: #0a84ff;
  --accent-color: #0a84ff;
  --accent-hover: #0070e0;
  --tag-bg: #2c2c2e;
  --tag-color: #0a84ff;
  --divider-color: #38383a;
}

/* 顶部个人信息区 */
.profile-header {
  position: relative;
  background: var(--bg-secondary);
  margin-bottom: 10px;
  transition: background 0.3s ease;
}

/* 主题切换按钮 */
.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 10;
}

.moments-app.dark-theme .theme-toggle {
  background: rgba(255, 255, 255, 0.2);
}

.theme-toggle:hover {
  transform: scale(1.1);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-icon {
  font-size: 20px;
}

.cover-image {
  width: 100%;
  height: 200px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.user-info {
  position: relative;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.avatar {
  width: 70px;
  height: 70px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffa07a 0%, #ff6b6b 100%);
  border: 3px solid white;
  margin-top: -35px;
}

.username {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
  margin-top: 10px;
  transition: color 0.3s ease;
}

/* 标签筛选栏 */
.filter-bar {
  max-width: 600px;
  margin: 0 auto 10px;
  padding: 15px;
  background: var(--bg-secondary);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  transition: background 0.3s ease;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.tag-filter {
  padding: 6px 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.tag-filter:active {
  transform: scale(0.98);
}

.tag-filter.active {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

/* 动态列表 */
.moments-list {
  max-width: 600px;
  margin: 0 auto;
}

/* 月份分隔线 */
.month-divider {
  padding: 15px 0;
  text-align: center;
  position: relative;
  margin: 10px 0;
}

.month-divider::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--divider-color), transparent);
}

.month-text {
  position: relative;
  background: var(--bg-primary);
  padding: 4px 20px;
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 1px;
  transition: all 0.3s ease;
}

.moment-item {
  background: var(--bg-secondary);
  padding: 15px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  transition: background 0.3s ease;
}

.moment-avatar {
  width: 45px;
  height: 45px;
  border-radius: 6px;
  background: linear-gradient(135deg, #ffa07a 0%, #ff6b6b 100%);
  flex-shrink: 0;
}

.moment-content {
  flex: 1;
  min-width: 0;
}

.moment-username {
  font-size: 16px;
  font-weight: bold;
  color: var(--link-color);
  margin-bottom: 5px;
  transition: color 0.3s ease;
}

.moment-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 10px;
  word-wrap: break-word;
  transition: color 0.3s ease;
}

/* 地点和标签区域 */
.moment-meta {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.moment-location {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--link-color);
  transition: color 0.3s ease;
}

.location-icon {
  font-size: 14px;
}

.location-text {
  line-height: 1.4;
}

/* 动态中的标签 */
.moment-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.moment-tags .tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--tag-bg);
  color: var(--tag-color);
  font-size: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.moment-tags .tag:active {
  background: var(--accent-color);
  color: white;
  transform: scale(0.95);
}

/* 图片展示 */
.moment-images {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.moment-images.image-count-1 {
  grid-template-columns: 1fr;
}

.image-wrapper.image-count-1 {
  max-width: 300px;
}

.moment-images:not(.image-count-1) {
  grid-template-columns: repeat(3, 1fr);
}

.image-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 100%;
  overflow: hidden;
  border-radius: 4px;
  background: #f0f2f5;
}

.image-wrapper img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 链接 */
.moment-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--link-color);
  margin-bottom: 10px;
  transition: all 0.3s ease;
}

.link-icon {
  font-size: 18px;
}

.link-text {
  font-size: 14px;
  word-break: break-all;
  flex: 1;
}

/* 底部信息 */
.moment-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.moment-time {
  font-size: 13px;
  color: var(--text-tertiary);
  transition: color 0.3s ease;
}

.moment-actions {
  display: flex;
  gap: 15px;
}

.like-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.like-btn:active {
  background: var(--bg-tertiary);
}

.like-btn.liked {
  color: #ff6b6b;
}

.like-icon {
  font-size: 16px;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  background: var(--bg-secondary);
  transition: all 0.3s ease;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 15px;
}

.empty-state p {
  margin: 5px 0;
  font-size: 14px;
}

/* 发布按钮 */
.post-btn {
  position: fixed;
  right: 20px;
  bottom: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  z-index: 100;
}

.post-btn:active {
  transform: scale(0.95);
}

.post-icon {
  font-size: 24px;
}

/* 弹窗 */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.dialog-content {
  background: var(--bg-secondary);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  transition: background 0.3s ease;
}

.moments-app.dark-theme .dialog-content {
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.dialog-header h3 {
  margin: 0;
  font-size: 18px;
  color: var(--text-primary);
  transition: color 0.3s ease;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease;
}

.dialog-body {
  padding: 20px;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
  transition: color 0.3s ease;
}

/* 图片列表 */
.image-list {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 2px;
}

.image-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  position: relative;
  transition: background 0.3s ease;
}

.image-preview {
  width: 50px;
  height: 50px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--border-color);
  transition: background 0.3s ease;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-url {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
  line-height: 1.4;
  transition: color 0.3s ease;
}

.remove-image-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ff6b6b;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.remove-image-btn:hover {
  background: #ff5252;
}

.remove-image-btn:active {
  transform: scale(0.95);
}

/* 添加图片区域 */
.add-image-section {
  display: flex;
  gap: 8px;
}

.add-image-section .url-input {
  flex: 1;
}

.add-image-btn {
  padding: 12px 20px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.add-image-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.add-image-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.add-image-btn:disabled {
  background: var(--text-tertiary);
  cursor: not-allowed;
  opacity: 0.6;
}

.image-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  transition: color 0.3s ease;
}

/* 标签列表 */
.tags-list {
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--tag-bg);
  color: var(--tag-color);
  border-radius: 16px;
  font-size: 13px;
  transition: all 0.3s ease;
}

.remove-tag-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.remove-tag-btn:hover {
  background: var(--accent-hover);
}

.remove-tag-btn:active {
  transform: scale(0.9);
}

/* 添加标签区域 */
.add-tag-section {
  display: flex;
  gap: 8px;
}

.add-tag-section .url-input {
  flex: 1;
}

.add-tag-btn {
  padding: 12px 20px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.add-tag-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.add-tag-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.add-tag-btn:disabled {
  background: var(--text-tertiary);
  cursor: not-allowed;
  opacity: 0.6;
}

.tag-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  transition: color 0.3s ease;
}

.text-input,
.url-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.text-input:focus,
.url-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.dialog-footer {
  display: flex;
  gap: 10px;
  padding: 20px;
  border-top: 1px solid var(--border-color);
  transition: border-color 0.3s ease;
}

.cancel-btn,
.publish-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.cancel-btn {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.publish-btn {
  background: var(--accent-color);
  color: white;
}

.cancel-btn:active,
.publish-btn:active {
  opacity: 0.8;
}

/* 移动端优化 */
@media (max-width: 600px) {
  .cover-image {
    height: 150px;
  }

  .avatar {
    width: 60px;
    height: 60px;
    margin-top: -30px;
  }

  .username {
    font-size: 16px;
  }

  .moment-item {
    padding: 12px;
  }

  .moment-avatar {
    width: 40px;
    height: 40px;
  }

  .dialog-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .dialog-content {
    border-radius: 12px 12px 0 0;
    max-height: 80vh;
  }
}
</style>
